<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
	
	//构造函数
	public function __construct(){
		parent::__construct();
		$this->user = D("user");
	}

	public function index(){
		echo "this is user index fun";
		//echo C("URL_PARAMS_BIND");
		// echo 111;
	}
	
	public function fun1($id,$age){
		echo "this fun1 params is".$id."and".$age;
	}
	 
	public function fun2(){
		//echo "this is fun2";
		//echo __EXT__ ;
		//echo "this is fun2";	
		echo U('User/fun2?id=1',array('cate_id'=>1,'status'=>1));
	}
	
	function fun3(){
		$data['user'] = "张三";
		$data['age'] = 44;
		// echo json_encode($data);
		//$this->ajaxReturn($data);
		$this->error("页面刷新成功");
		//$this->success('操作完成',U("user/fun2"),3);
		// $this->success('操作完成',"/tp/index.php/user/fun2",3);
		
	}
	
	public function fun4(){
		$str = $_GET['aaa'];
		var_dump($str);
	}
	
	
	public function _empty($name){
		//echo $name."这个方法找不到了,~~~~";
		//$this->redirect("http://www.baidu.com");
		redirect("http://www.baidu.com");
	}
	
	
	public function testModel(){
		// $user = D("User");
		//使用模型
		$data = $this->user->user(["id"=>42]);
		// $data = $user->where("id=42")->select();
		// $data = $user->where(array("id"=>1))->select();
		// $data = $user->where(array("id"=>1))->select();
		// $data = $user->table("user as a")->where(array("id"=>11))->select();
			//连表查询
		    // $data = $user->field('u.name,r.time')->table('user u,reply r')->where("u.id=r.uid")->select();


		// $data = $user->field(array("id","name"))->where(array("id"=>1))->select();
		// $data = $user->field(array("id","name"))->limit(2)->select();
		// $data = $user->field('name,max(money)')->group('name')->select();
		//关注用户
		//$data = $user->user();
		var_dump($data);
	}
	
	
	public function testSelect(){
		$user = D("User");
		$data = $user->distinct(true)->field('name')->select();
		//单条数据
		$data = $user->where("id = 42")->find();
		
		var_dump($data);
	}
}